/*
 * Copyright (C) 2011 Johan Kannala
 *
 * Licensed under the MIT License. You can find a copy of the License at in the
 * license.txt file.
 */
package com.joppe.vocabtutor.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.*;

/**
 * @author joppe
 *
 */
public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
	private Checkable checkableView = null;
	/**
	 * @param context
	 */
	public CheckableRelativeLayout(Context context) {
		super(context);
	}

	/**
	 * @param context
	 * @param attrs
	 */
	public CheckableRelativeLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		int noChildren = getChildCount();
		for (int childIdx = 0; childIdx < noChildren; childIdx++) {
			View child = getChildAt(childIdx);
			if (child instanceof Checkable) {
				checkableView = (Checkable) child;
				break;
			}
		}
	}
	
	/* (non-Javadoc)
	 * @see android.widget.Checkable#setChecked(boolean)
	 */
	@Override
	public void setChecked(boolean checked) {
		checkableView.setChecked(checked);
	}

	/* (non-Javadoc)
	 * @see android.widget.Checkable#isChecked()
	 */
	@Override
	public boolean isChecked() {
		return checkableView.isChecked();
	}

	/* (non-Javadoc)
	 * @see android.widget.Checkable#toggle()
	 */
	@Override
	public void toggle() {
		checkableView.toggle();
	}
}
